
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>缓存 · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="缓存.html" />
    
    
    <link rel="prev" href="熔断Hystrix.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="限流.html">
            
                <a href="限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="熔断Hystrix.html">
            
                <a href="熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.7" data-path="缓存.html">
            
                <a href="缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="缓存.html">
            
                <a href="缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="分布式事务.html">
            
                <a href="分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="分布式事务.html">
            
                <a href="分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="分布式定时作业.html">
            
                <a href="分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="分布式系统及CAP原理.html">
            
                <a href="分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../MQ/RabbitMQ笔记.html">
            
                <a href="../MQ/RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Mysql/经典数据库设计案例.html">
            
                <a href="../Mysql/经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Mysql/Mysql事务与锁.html">
            
                <a href="../Mysql/Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Mysql/mysql数据类型.html">
            
                <a href="../Mysql/mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../Mysql/mysql性能测试.html">
            
                <a href="../Mysql/mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../Mysql/mysql主从同步与读写分离.html">
            
                <a href="../Mysql/mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >缓存</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x7F13;&#x5B58;">&#x7F13;&#x5B58;</h1>
<p><a href="http://naotu.baidu.com/file/ee3cfa9404376168106e03f3539e43c4?token=3e515ebb102de098" target="_blank">&#x7F13;&#x5B58;&#x8111;&#x56FE;</a></p>
<hr>
<h1 id="&#x4E1A;&#x52A1;&#x573A;&#x666F;">&#x4E1A;&#x52A1;&#x573A;&#x666F;</h1>
<p>&#x603B;&#x7ED3;&#x90E8;&#x5206;&#x6709;&#x522B;&#x4E8E;&#x666E;&#x901A;&#x60C5;&#x51B5;&#x7684;&#x7F13;&#x5B58;&#x4F7F;&#x7528;&#x573A;&#x666F;</p>
<h2 id="&#x79D2;&#x6740;&#x573A;&#x666F;">&#x79D2;&#x6740;&#x573A;&#x666F;</h2>
<p>&#x5927;&#x591A;&#x6570;&#x9075;&#x5FAA;&#x4EE5;&#x4E0B;&#x7684;&#x7F13;&#x5B58;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ol>
<li>&#x67E5;&#x7F13;&#x5B58;</li>
<li>&#x6CA1;&#x7F13;&#x5B58;&#x5219;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x52A0;&#x8F7D;</li>
<li>&#x63D2;&#x5165;&#x7F13;&#x5B58;</li>
</ol>
<pre><code class="lang-java"><span class="hljs-keyword">private</span> Map cache = <span class="hljs-keyword">new</span> ConcurenthashMap();

<span class="hljs-function">Object <span class="hljs-title">getFromCache</span><span class="hljs-params">(String Key)</span></span>{
    Object value = cache.get(key);
    <span class="hljs-keyword">if</span>(value == <span class="hljs-keyword">null</span>){
        value = getFromSource(key);
        cache.put(key, value);
    }
}
</code></pre>
<p><img src="assets/1574749841378.png" alt="1574749841378"></p>
<p>&#x5BF9;&#x4E8E;&#x79D2;&#x6740;&#x573A;&#x666F;&#xFF0C;&#x4F8B;&#x5982;&#x96F6;&#x5143;&#x8D2D;&#x3001;&#x62A2;&#x8D2D;&#x3001;&#x62BD;&#x5956;&#x6216;&#x5176;&#x4ED6;&#x77AC;&#x65F6;&#x9AD8;&#x5E76;&#x53D1;&#x573A;&#x666F;&#xFF0C;&#x4F7F;&#x7528;&#x4EE5;&#x4E0A;&#x7F13;&#x5B58;&#x903B;&#x8F91;&#x662F;&#x4E0D;&#x53EF;&#x884C;&#x7684;&#x3002;&#x5982;&#x679C;&#x8BBE;&#x8BA1;&#x4E0D;&#x5F53;&#xFF0C;&#x7531;&#x4E8E;&#x9996;&#x6B21;&#x8BBF;&#x95EE;&#xFF0C;&#x6570;&#x636E;&#x6CA1;&#x6709;&#x52A0;&#x8F7D;&#x5230;&#x7F13;&#x5B58;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5927;&#x6D41;&#x91CF;&#x77AC;&#x65F6;&#x51B2;&#x5165;&#x6570;&#x636E;&#x5E93;&#x3001;&#x6216;&#x8C03;&#x7528;&#x5916;&#x90E8;&#x670D;&#x52A1;&#xFF0C;&#x6709;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x96EA;&#x5D29;&#x7684;&#x60C5;&#x51B5;&#x3002;</p>
<blockquote>
<p>&#x5927;&#x6D41;&#x91CF;&#x5E76;&#x53D1;&#x8BBF;&#x95EE;<code>if(value == null)</code>&#xFF0C;&#x53EA;&#x6709;&#x7B2C;&#x4E00;&#x6761;&#x7EBF;&#x7A0B;&#x52A0;&#x8F7D;&#x6570;&#x636E;&#xFF0C;&#x540E;&#x7EED;&#x7EBF;&#x7A0B;&#x624D;&#x80FD;&#x547D;&#x4E2D;&#x7F13;&#x5B58;&#xFF1B;&#x53CD;&#x4E4B;&#xFF0C;&#x5982;&#x679C;<code>getFromSource()</code>&#x65B9;&#x6CD5;&#x8BF7;&#x6C42;&#x8D44;&#x6E90;&#x6709;&#x963B;&#x585E;&#xFF0C;&#x6240;&#x6709;&#x6D41;&#x91CF;&#x90FD;&#x4F1A;&#x901A;&#x8FC7;<code>value == null</code>&#x7684;&#x5224;&#x65AD;&#x51B2;&#x51FB;&#x8BF7;&#x6C42;&#x8D44;&#x6E90;&#xFF0C;&#x7F13;&#x5B58;&#x6839;&#x672C;&#x6CA1;&#x6709;&#x8D77;&#x5230;&#x4FDD;&#x62A4;&#x8D44;&#x6E90;&#x7684;&#x4F5C;&#x7528;</p>
</blockquote>
<p><strong>&#x603B;&#x7ED3;&#x5C31;&#x662F;&#xFF1A;&#x7F13;&#x5B58;&#x6CA1;&#x751F;&#x6548;&#xFF0C;&#x5927;&#x91CF;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x88C5;&#x8F7D;&#x6570;&#x636E;</strong></p>
<p><strong>&#x89E3;&#x51B3;&#x65B9;&#x6848;1</strong></p>
<blockquote>
<p>&#x52A0;&#x8F7D;&#x6570;&#x636E;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x52A0;&#x9501;&#xFF0C;&#x907F;&#x514D;&#x591A;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x88C5;&#x8F7D;&#xFF1B;</p>
</blockquote>
<p><img src="assets/1574749871970.png" alt="1574749871970"></p>
<p>&#x9488;&#x5BF9;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#xFF0C;&#x9996;&#x5148;&#x60F3;&#x5230;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x52A0;&#x9501;&#x907F;&#x514D;&#x5E76;&#x53D1;&#x88C5;&#x8F7D;&#x6570;&#x636E;&#xFF0C;&#x5BF9;&#x4E8E;&#x540C;&#x4E00;&#x4EFD;&#x9700;&#x8981;&#x88C5;&#x8F7D;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x9700;&#x8981;&#x52A0;&#x9501;&#x907F;&#x514D;&#x591A;&#x4E2A;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x88C5;&#x8F7D;&#x3002;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x5728;&#x7B49;&#x5F85;&#x88C5;&#x8F7D;&#x6570;&#x636E;&#xFF0C;&#x5176;&#x4ED6;&#x7EBF;&#x7A0B;&#x5E94;&#x8BE5;&#x7B49;&#x5F85;&#x5B83;&#x5B8C;&#x6210;&#x88C5;&#x8F7D;&#x3002;&#x6570;&#x636E;&#x88C5;&#x8F7D;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;&#x7B49;&#x5F85;&#x4E2D;&#x7684;&#x5176;&#x4ED6;&#x5DE5;&#x4F5C;&#x7EBF;&#x7A0B;&#x5E94;&#x8BE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x65B0;&#x88C5;&#x8F7D;&#x7684;&#x6570;&#x636E;</p>
<pre><code class="lang-java"><span class="hljs-keyword">private</span> Map cache = <span class="hljs-keyword">new</span> ConcurenthashMap();

<span class="hljs-function">Object <span class="hljs-title">getFromCache</span><span class="hljs-params">(String Key)</span></span>{
    lock(<span class="hljs-keyword">this</span>) { <span class="hljs-comment">// or sync</span>
        Object value = cache.get(key);
        <span class="hljs-keyword">if</span>(value == <span class="hljs-keyword">null</span>){
            value = getFromSource(key);
            cache.put(key, value);
        }
    }
}
</code></pre>
<p><strong>&#x6F5C;&#x5728;&#x95EE;&#x9898;</strong>&#xFF1A;</p>
<ol>
<li>&#x5BF9;&#x4E8E;&#x5355;&#x4E2A;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#x800C;&#x8A00;&#xFF0C;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x90FD;&#x8981;&#x4E32;&#x884C;&#x5316;&#x53BB;&#x52A0;&#x8F7D;&#x7F13;&#x5B58;&#x6216;&#x88C5;&#x8F7D;&#x6570;&#x636E;</li>
<li>&#x4F7F;&#x7528;&#x9501;&#x7684;&#x5F00;&#x9500;&#x975E;&#x5E38;&#x5927;</li>
</ol>
<p>&#x663E;&#x7136;&#x8BE5;&#x65B9;&#x6848;&#x662F;&#x4E0D;&#x53EF;&#x884C;&#x7684;</p>
<p><strong>&#x89E3;&#x51B3;&#x65B9;&#x6848;2</strong></p>
<blockquote>
<p>&#x79D2;&#x6740;&#x524D;&#xFF0C;&#x4F18;&#x5148;&#x5C06;&#x6570;&#x636E;&#x52A0;&#x8F7D;&#x5230;&#x7F13;&#x5B58;</p>
</blockquote>
<p>&#x4F18;&#x5148;&#x88C5;&#x8F7D;&#x7F13;&#x5B58;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#xFF0C;&#x4F46;&#x7531;&#x6B64;&#x5F15;&#x7533;&#x4E24;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;</p>
<ol>
<li>&#x529F;&#x80FD;&#x590D;&#x6742;&#xFF1B;</li>
<li>&#x8981;&#x8003;&#x8651;&#x7F13;&#x5B58;&#x4E0E;&#x6E90;&#x6570;&#x636E;&#x7684;&#x4E00;&#x81F4;&#x6027;&#x95EE;&#x9898;</li>
</ol>
<p>&#x529F;&#x80FD;&#x56E0;&#x6B64;&#x53D8;&#x5F97;&#x590D;&#x6742;&#x662F;&#x53EF;&#x4EE5;&#x9884;&#x89C1;&#xFF0C;&#x4F8B;&#x5982;&#x62A2;&#x8D2D;&#x529F;&#x80FD;&#xFF0C;&#x9700;&#x8981;&#x63D0;&#x524D;&#x5C06;&#x5E93;&#x5B58;&#x63A8;&#x9001;&#x5230;&#x7F13;&#x5B58;&#x4E2D;&#xFF1B;&#x5F53;&#x9700;&#x6C42;&#x6709;&#x53D8;&#x65F6;&#xFF0C;&#x4F8B;&#x5982;&#x5206;&#x65F6;&#x95F4;&#x6BB5;&#x7684;&#x62A2;&#x8D2D;&#x6D3B;&#x52A8;&#xFF0C;&#x6574;&#x5757;&#x529F;&#x80FD;&#x7684;&#x590D;&#x6742;&#x6027;&#x5C06;&#x4F1A;&#x5927;&#x5927;&#x63D0;&#x5347;&#x3002;</p>
<p>&#x800C;&#x6570;&#x636E;&#x4E00;&#x81F4;&#x6027;&#x95EE;&#x9898;&#x53C2;&#x8003;<a href="../&#x8BBE;&#x8BA1;/&#x79D2;&#x6740;.md">&#x79D2;&#x6740;&#x7CFB;&#x7EDF;&#x8BBE;&#x8BA1;</a></p>
<h2 id="&#x65AD;&#x5D16;&#x5F0F;&#x4E0B;&#x6ED1;">&#x65AD;&#x5D16;&#x5F0F;&#x4E0B;&#x6ED1;</h2>
<p>&#x6709;&#x4E1A;&#x52A1;&#x573A;&#x666F;&#x5F53;&#x6D41;&#x91CF;&#x8DB3;&#x591F;&#x5927;&#x4E14;&#x5E73;&#x6ED1;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x89C2;&#x5BDF;&#x5230;&#x541E;&#x5410;&#x91CF;&#x968F;&#x7740;&#x65F6;&#x95F4;&#x7684;&#x53D8;&#x5316;&#x5448;&#x5982;&#x4E0B;&#x5173;&#x7CFB;</p>
<p><img src="assets/1574750845410.png" alt="1574750845410"></p>
<p>QPS&#x6709;&#x89C4;&#x5F8B;&#x5730;&#x5468;&#x671F;&#x6027;&#x65AD;&#x5D16;&#x5F0F;&#x4E0B;&#x6ED1;&#xFF0C;&#x7ECF;&#x8FC7;&#x6D4B;&#x8BD5;&#x5F97;&#x51FA;&#xFF0C;&#x65AD;&#x5D16;&#x4F4D;&#x7F6E;&#x90FD;&#x662F;&#x7F13;&#x5B58;&#x8FC7;&#x671F;&#x65F6;&#xFF0C;&#x77AC;&#x65F6;&#x5168;&#x90E8;&#x8BF7;&#x6C42;&#x91CD;&#x65B0;&#x88C5;&#x8F7D;&#x6570;&#x636E;&#x5BFC;&#x81F4;&#x7684;&#xFF1B;&#x4F46;&#x7F13;&#x5B58;&#x91CD;&#x65B0;&#x88C5;&#x8F7D;&#x6570;&#x636E;&#x540E;&#xFF0C;QPS&#x91CD;&#x65B0;&#x6062;&#x590D;&#x5230;&#x9AD8;&#x5EA6;&#x3002;</p>
<p><strong>&#x89E3;&#x51B3;&#x65B9;&#x6848;3&#xFF1A;</strong>&#x4E0E;&#x65B9;&#x6848;2&#x7684;&#x601D;&#x8DEF;&#x4E00;&#x81F4;&#x7684;&#x662F;&#xFF1A;<strong>&#x59CB;&#x7EC8;&#x53EA;&#x6709;&#x4E00;&#x6761;&#x7EBF;&#x7A0B;&#x66F4;&#x65B0;&#x7F13;&#x5B58;&#x6570;&#x636E;</strong>&#xFF0C;&#x4F46;&#x4E0D;&#x540C;&#x7684;&#x662F;<strong>&#x5176;&#x4ED6;&#x7EBF;&#x7A0B;&#x4E0D;&#x963B;&#x585E;&#x4E0D;&#x7B49;&#x5F85;</strong>&#xFF0C;&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#x7F13;&#x5B58;&#x6570;&#x636E;&#x3002;&#x800C;&#x505A;&#x5230;&#x8FD9;&#x4E00;&#x70B9;&#x7684;&#x5173;&#x952E;&#x662F;&#xFF0C;&#x7F13;&#x5B58;&#x8FC7;&#x671F;&#x7B56;&#x7565;&#x8C03;&#x6574;&#x4E3A;<strong>&#x4E0D;&#x8FC7;&#x671F;</strong>&#xFF0C;&#x800C;&#x662F;<strong>&#x8FDB;&#x7A0B;&#x4E3B;&#x52A8;&#x66F4;&#x65B0;&#x7F13;&#x5B58;</strong>&#x3002;</p>
<p>Guava LoadingCache&#x89E3;&#x51B3;&#x63D0;&#x4F9B;&#x7C7B;&#x4F3C;&#x7684;&#x65B9;&#x6848;&#xFF0C;&#x53C2;&#x8003;<a href="#Guava-LoadingCache">Guava-LoadingCache</a></p>
<pre><code class="lang-java"><span class="hljs-meta">@Test</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testMultiThreadAndReloadAsync</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
    LoadingCache&lt;String, String&gt; cache = CacheBuilder.newBuilder()
        .refreshAfterWrite(<span class="hljs-number">100</span>, TimeUnit.MILLISECONDS)
        .removalListener(<span class="hljs-keyword">new</span> RemovalListener&lt;String, String&gt;() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onRemoval</span><span class="hljs-params">(RemovalNotification&lt;String, String&gt; removalNotification)</span> </span>{
                System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;-remove key:&quot;</span> + removalNotification.getKey());
                System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;-remove value:&quot;</span> + removalNotification.getValue());
            }
        })
        .build(<span class="hljs-keyword">new</span> CacheLoader&lt;String, String&gt;() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">load</span><span class="hljs-params">(String key)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
                System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;start loading&quot;</span>);
                value++;
                String output = String.valueOf(value);
                Thread.sleep(<span class="hljs-number">1000L</span>);
                System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;load from db:&quot;</span> + output);
                <span class="hljs-keyword">return</span> output;
            }
        });


    <span class="hljs-comment">//&#x6B64;&#x5916;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E2A;&#x70B9;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;&#x5B9A;&#x65F6;&#x5E76;&#x4E0D;&#x662F;&#x771F;&#x6B63;&#x610F;&#x4E49;&#x4E0A;&#x7684;&#x5B9A;&#x65F6;&#x3002;Guava cache&#x7684;&#x5237;&#x65B0;&#x9700;&#x8981;&#x4F9D;&#x9760;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x7EBF;&#x7A0B;&#xFF0C;&#x8BA9;&#x8BE5;&#x7EBF;&#x7A0B;&#x53BB;&#x8FDB;&#x884C;load&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#x5982;&#x679C;&#x4E00;&#x76F4;&#x6CA1;&#x6709;&#x7528;&#x6237;&#x5C1D;&#x8BD5;&#x83B7;&#x53D6;&#x8BE5;&#x7F13;&#x5B58;&#x503C;&#xFF0C;&#x5219;&#x8BE5;&#x7F13;&#x5B58;&#x4E5F;&#x5E76;&#x4E0D;&#x4F1A;&#x5237;&#x65B0;&#x3002;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">5</span>; i++) {
        Thread thread3 = <span class="hljs-keyword">new</span> Thread(() -&gt; {
            <span class="hljs-keyword">while</span> (<span class="hljs-keyword">true</span>) {
                <span class="hljs-keyword">try</span> {
                    Thread.sleep((<span class="hljs-keyword">long</span>) (Math.random() * <span class="hljs-number">1000</span>));

                    getAndReload(cache);
                } <span class="hljs-keyword">catch</span> (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        });
        thread3.start();
    }

    Thread.sleep(<span class="hljs-number">800000L</span>);
}

<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">getAndReload</span><span class="hljs-params">(LoadingCache&lt;String, String&gt; cache)</span> </span>{
    <span class="hljs-keyword">try</span> {
        String result = cache.get(<span class="hljs-string">&quot;key&quot;</span>);
        System.out.println(Thread.currentThread().getName() + <span class="hljs-string">&quot;:get from cache:&quot;</span> + result);

    } <span class="hljs-keyword">catch</span> (ExecutionException ex) {
        ex.printStackTrace();
    }
}
</code></pre>
<h2 id="&#x6E05;&#x7406;&#x5173;&#x8054;&#x7F13;&#x5B58;">&#x6E05;&#x7406;&#x5173;&#x8054;&#x7F13;&#x5B58;</h2>
<p>&#x5206;&#x9875;&#x6570;&#x636E;&#x53D1;&#x751F;&#x9891;&#x7E41;&#x53D8;&#x66F4;&#x65F6;&#xFF0C;&#x53EF;&#x80FD;&#x7531;&#x4E8E;&#x6E05;&#x7406;&#x5173;&#x8054;&#x7F13;&#x5B58;&#x4E0D;&#x5F53;&#xFF0C;&#x5BFC;&#x81F4;&#x51FA;&#x9519;&#x3002;</p>
<p>&#x4E3E;&#x4F8B;&#x4E1A;&#x52A1;&#x573A;&#x666F;&#xFF1A;&#x62A2;&#x8D2D;&#x529F;&#x80FD;&#xFF0C;&#x62A2;&#x5B8C;&#x540E;&#x663E;&#x793A;&#x62A2;&#x8D2D;&#x8BB0;&#x5F55;&#xFF0C;&#x8BB0;&#x5F55;&#x4EE5;&#x62A2;&#x8D2D;&#x91D1;&#x989D;<strong>&#x5012;&#x5E8F;</strong>&#xFF0C;&#x8D2D;&#x4E70;&#x91D1;&#x989D;&#x6700;&#x9AD8;&#x7684;&#x7528;&#x6237;&#x6709;&#x989D;&#x5916;&#x5956;&#x52B1;&#x6807;&#x8BC6;</p>
<p><img src="assets/1574757806374.png" alt="1574757806374"></p>
<ol>
<li>&#x7528;&#x6237;&#x5728;&#x6709;4&#x4E2A;&#x4EBA;&#x62A2;&#x8D2D;&#x60C5;&#x51B5;&#x4E0B;&#x6253;&#x5F00;&#x529F;&#x80FD;&#xFF0C;&#x53EA;&#x505C;&#x7559;&#x5728;&#x7B2C;1&#x9875;&#xFF0C;&#x5373;3&#x5217;&#x7684;&#x7B2C;1&#x9875;&#x3010;D,C,B&#x3011;</li>
<li>&#x7B2C;5&#x4E2A;&#x4EBA;&#x62A2;&#x8D2D;&#x540E;&#xFF0C;&#x5B9E;&#x9645;&#x72B6;&#x6001;&#x4ECE;1&#x5217;&#x53D8;&#x6210;2&#x5217;</li>
<li>&#x7528;&#x6237;&#x6253;&#x5F00;&#x7B2C;2&#x9875;&#xFF0C;&#x7531;&#x4E8E;&#x7F13;&#x5B58;&#x88AB;&#x5237;&#xFF0C;&#x67E5;&#x8BE2;&#x6240;&#x5F97;&#x4E3A;4&#x5217;&#x7684;&#x7B2C;2&#x9875;&#x3010;B,A&#x3011;</li>
</ol>
<p>&#x6700;&#x540E;&#xFF0C;&#x663E;&#x793A;&#x7ED3;&#x679C;&#x6709;&#x91CD;&#x590D;&#xFF0C;&#x9020;&#x6210;&#x6B67;&#x4E49;</p>
<p><strong>&#x89E3;&#x51B3;&#x65B9;&#x6848;</strong></p>
<p><img src="assets/1574762207096.png" alt="1574762207096"></p>
<ol>
<li>&#x540E;&#x7AEF;&#x6839;&#x636E;&#x4E0D;&#x540C;version&#xFF0C;&#x4FDD;&#x7559;&#x591A;&#x4EFD;&#x7F13;&#x5B58;&#xFF1B;</li>
<li>&#x5BA2;&#x6237;&#x7AEF;&#x67E5;&#x9996;&#x9875;&#x65F6;&#xFF0C;&#x83B7;&#x53D6;&#x6700;&#x65B0;version&#x5BF9;&#x5E94;&#x7684;&#x6570;&#x636E;&#xFF1B;</li>
<li>&#x67E5;&#x8BE2;&#x9996;&#x9875;&#x4EE5;&#x5916;&#x9875;&#x9762;&#x65F6;&#xFF0C;&#x6839;&#x636E;&#x5BA2;&#x6237;&#x7AEF;&#x81EA;&#x8EAB;&#x6301;&#x6709;version&#x67E5;&#x8BE2;&#x5BF9;&#x5E94;&#x6570;&#x636E;</li>
<li>&#x6570;&#x636E;&#x66F4;&#x65B0;&#x65F6;&#xFF0C;&#x7248;&#x672C;&#x9012;&#x589E;&#x52A0;1</li>
</ol>
<h2 id="&#x6E05;&#x7406;&#x4E8C;&#x7EA7;&#x7F13;&#x5B58;">&#x6E05;&#x7406;&#x4E8C;&#x7EA7;&#x7F13;&#x5B58;</h2>
<p>&#x5206;&#x5E03;&#x5F0F;&#x7F13;&#x5B58;&#x901A;&#x77E5;&#x673A;&#x5236;</p>
<ol>
<li><a href="../Redis/Redis.html#&#x6D88;&#x606F;&#x8BA2;&#x9605;">Redis&#x6D88;&#x606F;&#x8BA2;&#x9605;</a></li>
<li>rabbitMQ</li>
</ol>
<hr>
<h1 id="&#x8FC7;&#x671F;&#x7B56;&#x7565;">&#x8FC7;&#x671F;&#x7B56;&#x7565;</h1>
<ol>
<li>&#x7F13;&#x5B58;&#x672A;&#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF0C;&#x4E24;&#x79CD;&#x7F13;&#x5B58;&#x65F6;&#x95F4;&#x8FC7;&#x671F;&#x673A;&#x5236;&#xFF1A;1)&#x3001;&#x4E0D;&#x518D;&#x8BFB;&#x5199;&#x7684;&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x540E;&#x5220;&#x9664;&#xFF1B;2&#xFF09;&#x3001;&#x6307;&#x5B9A;&#x5199;&#x5165;&#x4E00;&#x5B9A;&#x65F6;&#x95F4;&#x540E;&#x5220;&#x9664;&#xFF1B;3&#xFF09;&#x3001;&#x6307;&#x5B9A;&#x7EDD;&#x5BF9;&#x65F6;&#x95F4;&#x540E;&#x8FC7;&#x671F;</li>
<li>&#x4E1A;&#x52A1;&#x4FDD;&#x62A4;&#x3001;&#x52A8;&#x6001;&#x8FC7;&#x671F;&#x7B56;&#x7565;</li>
</ol>
<hr>
<h1 id="&#x672C;&#x5730;&#x7F13;&#x5B58;">&#x672C;&#x5730;&#x7F13;&#x5B58;</h1>
<h2 id="spring-boot-cache">Spring Boot Cache</h2>
<p>TODO</p>
<hr>
<h2 id="guava-loadingcache">Guava-LoadingCache</h2>
<h3 id="&#x5237;&#x65B0;&#x673A;&#x5236;">&#x5237;&#x65B0;&#x673A;&#x5236;</h3>
<p>LoadingCache&#x5982;&#x4F55;&#x89E3;&#x51B3;<a href="#&#x65AD;&#x5D16;&#x5F0F;&#x4E0B;&#x6ED1;">&#x65AD;&#x5D16;&#x5F0F;&#x4E0B;&#x6ED1;</a>&#xFF1F;</p>
<p><img src="assets/1574751917536.png" alt="1574751917536"></p>
<ol>
<li>&#x9996;&#x5148;&#x7F13;&#x5B58;&#x4E0D;&#x8FC7;&#x671F;&#xFF1B;</li>
<li>&#x7B2C;&#x4E00;&#x6761;&#x7EBF;&#x7A0B;&#x67E5;&#x7F13;&#x5B58;&#x65F6;&#xFF0C;&#x53D1;&#x73B0;&#x5DF2;&#x8FC7;<code>refreshAfterWrite</code>&#x5237;&#x65B0;&#x65F6;&#x95F4;&#xFF0C;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x67E5;&#x5E93;&#x8BF7;&#x6C42;&#xFF1B;</li>
<li>&#x5176;&#x4ED6;&#x7EBF;&#x7A0B;&#x4E0D;&#x7B49;&#x5F85;&#x4E0D;&#x963B;&#x585E;&#xFF0C;&#x7EE7;&#x7EED;&#x8FD4;&#x56DE;<strong>&#x65E7;&#x7F13;&#x5B58;</strong>&#x6570;&#x636E;&#xFF1B;</li>
<li>&#x7B2C;&#x4E00;&#x6761;&#x7EBF;&#x7A0B;&#x5B8C;&#x6210;&#x6570;&#x636E;&#x88C5;&#x8F7D;&#x540E;&#xFF0C;&#x66FF;&#x6362;&#x65E7;&#x7F13;&#x5B58;&#x6570;&#x636E;&#x3002;</li>
</ol>
<h3 id="get&#x4E0E;getifpresent&#x533A;&#x522B;">get()&#x4E0E;getIfPresent()&#x533A;&#x522B;</h3>
<ol>
<li><code>V get(K k)</code>: &#x5185;&#x90E8;&#x8C03;&#x7528;getOrLoad(K key)&#x65B9;&#x6CD5;&#xFF0C;&#x7F13;&#x5B58;&#x4E2D;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x5219;&#x8FD4;&#x56DE;&#xFF0C;&#x6CA1;&#x6709;&#x5219;&#x4F7F;&#x7528;CacheLoader load&#x65B9;&#x6CD5;getOrLoad(K key)&#x65B9;&#x6CD5;&#x4E3A;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x65B9;&#x6CD5;&#xFF0C;&#x5185;&#x90E8;&#x52A0;&#x9501;</li>
<li><code>V getIfPresent(Object key)</code>:&#x7F13;&#x5B58;&#x4E2D;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x5219;&#x8FD4;&#x56DE;&#xFF0C;&#x6CA1;&#x6709;&#x5219;&#x8FD4;&#x56DE;NULL</li>
</ol>
<h3 id="&#x5237;&#x65B0;&#x65F6;&#x95F4;&#x4E0E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;">&#x5237;&#x65B0;&#x65F6;&#x95F4;&#x4E0E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;</h3>
<blockquote>
<p>expireAfterAccess&#xFF08;expireAfterWrite&#xFF09;&#x4E0E;refreshAfterWrite</p>
</blockquote>
<ol>
<li>expireAfterAccess&#xFF1A;&#x7F13;&#x5B58;&#x9879;&#x5728;&#x521B;&#x5EFA;&#x540E;&#xFF0C;&#x5728;&#x7ED9;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x6CA1;&#x6709;&#x88AB;&#x8BFB;/&#x5199;&#x8BBF;&#x95EE;&#xFF0C;&#x5219;&#x6E05;&#x9664;</li>
<li>expireAfterWrite&#xFF1A;&#x7F13;&#x5B58;&#x9879;&#x5728;&#x521B;&#x5EFA;&#x540E;&#xFF0C;&#x5728;&#x7ED9;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x6CA1;&#x6709;&#x5199;&#x8BBF;&#x95EE;&#xFF0C;&#x5219;&#x6E05;&#x9664;</li>
<li>refreshAfterWrite&#xFF1A;&#x7F13;&#x5B58;&#x9879;&#x5728;&#x521B;&#x5EFA;&#x540E;&#xFF0C;&#x5B9A;&#x65F6;&#x4ECE;cacheLoader&#x68C0;&#x7D22;data&#x5E76;&#x5237;&#x65B0;&#x7F13;&#x5B58;</li>
</ol>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x65E0;&#x8BBA;&#x662F;expire&#x6216;refresh&#xFF0C;&#x90FD;&#x662F;&#x901A;&#x8FC7;&#x5B9E;&#x9645;&#x8BF7;&#x6C42;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x7F13;&#x5B58;&#x9879;&#x88AB;&#x68C0;&#x7D22;&#x65F6;&#x89E6;&#x53D1;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8BF7;&#x6C42;&#xFF0C;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x4E5F;&#x4E0D;&#x4F1A;&#x8FC7;&#x671F;&#x6216;&#x5237;&#x65B0;</p>
<ol>
<li>&#x901A;&#x8FC7;&#x5B9A;&#x65F6;&#x5237;&#x65B0;&#x53EF;&#x4EE5;&#x8BA9;&#x7F13;&#x5B58;&#x9879;&#x4FDD;&#x6301;&#x53EF;&#x7528;&#xFF0C;&#x4F46;&#x8BF7;&#x6CE8;&#x610F;&#xFF1A;&#x7F13;&#x5B58;&#x9879;&#x53EA;&#x6709;&#x5728;&#x88AB;&#x68C0;&#x7D22;&#x65F6;&#x624D;&#x4F1A;&#x771F;&#x6B63;&#x5237;&#x65B0;&#xFF0C;
&#x5373;&#x53EA;&#x6709;&#x5237;&#x65B0;&#x95F4;&#x9694;&#x65F6;&#x95F4;&#x5230;&#x4E86;&#x4F60;&#x518D;&#x53BB;get(key)&#x624D;&#x4F1A;&#x91CD;&#x65B0;&#x53BB;&#x6267;&#x884C;Loading&#x5426;&#x5219;&#x5C31;&#x7B97;&#x5237;&#x65B0;&#x95F4;&#x9694;&#x65F6;&#x95F4;&#x5230;&#x4E86;&#x4E5F;&#x4E0D;&#x4F1A;&#x6267;&#x884C;loading&#x64CD;&#x4F5C;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5982;&#x4F60;&#x5728;&#x7F13;&#x5B58;&#x4E0A;&#x540C;&#x65F6;&#x58F0;&#x660E;expireAfterWrite&#x548C;refreshAfterWrite&#xFF0C;&#x7F13;&#x5B58;&#x5E76;&#x4E0D;&#x4F1A;&#x56E0;&#x4E3A;&#x5237;&#x65B0;&#x76F2;&#x76EE;&#x5730;&#x5B9A;&#x65F6;&#x91CD;&#x7F6E;&#x5982;&#x679C;&#x7F13;&#x5B58;&#x9879;&#x6CA1;&#x6709;&#x88AB;&#x68C0;&#x7D22;&#xFF0C;&#x90A3;&#x5237;&#x65B0;&#x5C31;&#x4E0D;&#x4F1A;&#x771F;&#x7684;&#x53D1;&#x751F;&#xFF0C;&#x7F13;&#x5B58;&#x9879;&#x5728;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#x540E;&#x4E5F;&#x53D8;&#x5F97;&#x53EF;&#x4EE5;&#x56DE;&#x6536;&#x3002;</li>
</ol>
</blockquote>
<pre><code class="lang-java">    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testLoadingCacheExpireAfterAccess2</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> InterruptedException, ExecutionException </span>{
        ThreadFactory threadFactory = <span class="hljs-keyword">new</span> ThreadFactoryBuilder()
                .setNameFormat(<span class="hljs-string">&quot;thread-%d&quot;</span>)
                .build();
        ExecutorService executorService = Executors.newCachedThreadPool(threadFactory);

        <span class="hljs-keyword">int</span> expireAfterAccess = <span class="hljs-number">300</span>;
        <span class="hljs-keyword">int</span> refreshAfterWrite = <span class="hljs-number">200</span>;
        LoadingCache&lt;String, String&gt; cache = CacheBuilder.newBuilder()
                <span class="hljs-comment">//&#x7F13;&#x5B58;&#x9879;&#x5728;&#x521B;&#x5EFA;&#x540E;&#xFF0C;&#x5728;&#x7ED9;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x6CA1;&#x6709;&#x88AB;&#x8BFB;/&#x5199;&#x8BBF;&#x95EE;&#xFF0C;&#x5219;&#x6E05;&#x9664;&#x3002;</span>
                .expireAfterAccess(expireAfterAccess, TimeUnit.MILLISECONDS)
                .refreshAfterWrite(refreshAfterWrite, TimeUnit.MILLISECONDS)
                .recordStats()
                .build(<span class="hljs-keyword">new</span> CacheLoader&lt;String, String&gt;() {
                    <span class="hljs-meta">@Override</span>
                    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">load</span><span class="hljs-params">(String key)</span> <span class="hljs-keyword">throws</span> Exception </span>{
                        System.out.println(<span class="hljs-string">&quot;loading from CacheLoader datasource &quot;</span>);
                        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;target value&quot;</span>;
                    }
                });


        Future submit = executorService
                .submit(() -&gt; {
                    <span class="hljs-keyword">while</span> (<span class="hljs-keyword">true</span>) {
                        String value = cache.get(<span class="hljs-string">&quot;key&quot;</span>);
                        System.out.println(value);
                        System.out.println(cache.stats());

                        <span class="hljs-keyword">try</span> {
                            <span class="hljs-comment">//&#x7EBF;&#x7A0B;&#x6302;&#x8D77;&#x65F6;&#x957F;&#x8D85;&#x8FC7;300&#x6BEB;&#x79D2;&#xFF0C;&#x7F13;&#x5B58;&#x4F1A;&#x8FC7;&#x671F;&#xFF0C;&#x4ECE;cacheLoader&#x4E2D;&#x52A0;&#x8F7D;</span>
                            <span class="hljs-comment">//&#x53CD;&#x4E4B;&#xFF0C;&#x82E5;&#x5C11;&#x4E8E;300&#x6BEB;&#x79D2;&#xFF0C;&#x7F13;&#x5B58;&#x6C38;&#x8FDC;&#x4E0D;&#x4F1A;&#x8FC7;&#x671F;</span>
                            TimeUnit.MILLISECONDS.sleep(<span class="hljs-number">50</span>);
                        } <span class="hljs-keyword">catch</span> (InterruptedException e1) {
                            Thread.currentThread().interrupt();
                        }
                    }
                });
        Thread.sleep(<span class="hljs-number">2000</span>);
        submit.cancel(<span class="hljs-keyword">true</span>);

        Thread.sleep(<span class="hljs-number">500</span>);
        String value = cache.get(<span class="hljs-string">&quot;key&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;last:&quot;</span> + value);
        System.out.println(<span class="hljs-string">&quot;last:&quot;</span> + cache.stats());
    }
</code></pre>
<h1 id="&#x5206;&#x5E03;&#x5F0F;&#x7F13;&#x5B58;redis">&#x5206;&#x5E03;&#x5F0F;&#x7F13;&#x5B58;Redis</h1>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-23 15:32:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="熔断Hystrix.html" class="navigation navigation-prev " aria-label="Previous page: 熔断Hystrix">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="缓存.html#本地缓存" class="navigation navigation-next " aria-label="Next page: 本地缓存">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"缓存","level":"1.2.7","depth":2,"next":{"title":"本地缓存","level":"1.2.8","depth":2,"anchor":"#本地缓存","path":"Java-其他库/缓存.md","ref":"Java-其他库/缓存.md#本地缓存","articles":[]},"previous":{"title":"熔断Hystrix","level":"1.2.6","depth":2,"path":"Java-其他库/熔断Hystrix.md","ref":"Java-其他库/熔断Hystrix.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"Java-其他库/缓存.md","mtime":"2020-04-23T07:32:53.352Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

